package com.hx.control;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hx.entity.CountInfo;
import com.hx.entity.Detail;
import com.hx.entity.InfoManage;
import com.hx.entity.Teacher;
import com.hx.service.CourseService;
import com.hx.service.InfoManageService;
import com.hx.service.TeacherService;
@RequestMapping("/manage")
@RestController
public class Manage {
      private List<InfoManage> infoManages;
      private List<Teacher> teachers;

      
      
      @Autowired
      private InfoManageService infoManageService;
      @Autowired
      private CourseService courseService;
      @Autowired
      private TeacherService teacherService;
    
      @RequestMapping("/getday")
        public List<String> getDay(){
        	return  infoManageService.getAllDate();
        }
        
      
      @RequestMapping("/getinfomanage/{date}")   /*请求infomanage*/
      public List<CountInfo> getInfo(@PathVariable("date") String date){
    	  List<CountInfo> coutInfos=new ArrayList<>();
    	  infoManages=infoManageService.getOneDay(date); 
    	  teachers=teacherService.getAll();
    	  for(int i=0;i<teachers.size();i++){
    		  double avg=0;                          //平均分
    		  String courseName="";                  //课程名
    		  CountInfo ci=new CountInfo();         //countinfo保存要传过去的数据  
    		  ci.setTeacherName(teachers.get(i).getName());
    		  for(InfoManage im:infoManages){
    			  if(im.getTeacher_Id()==teachers.get(i).getId()){
    				  ci.getItems().add(new Detail(im.getSession_Id(),im.getScore_Sum(),im.getSuggest(),im.getDetails()));
    				  /*items 包括评价的学生编号  学生评分  项目每一个内容的得分details集合 */
    				  avg+=im.getScore_Sum();
    				  courseName=courseService.getOne(im.getCourses_Id()).getName();
    			  }
    		  }
    		  ci.setCoursesName(courseName);
    		  ci.setScore_Man(ci.getItems().size());
    		  ci.setAvg(avg/ci.getItems().size());
    		  coutInfos.add(ci);
    		  
    	  }
    	  return coutInfos;
      }
}
